<template>
  <div class="container">
    <div class="package-card bg-white hd-shadow">

      <van-row>
        <van-search
                v-model="value"
                placeholder="请输入查询线路号"
                show-action
                @search="onSearch"
                :label="cityname"
        >
          <div slot="action" @click="onSearch">搜索</div>
        </van-search>

      </van-row>
      <van-tabs v-model="active" sticky class="shop-list">
        <van-tab title="去程">
          <van-cell :title="goitem" :label="goinfo" />
          <van-cell-group>
            <van-cell
                    v-for="(item, index) in golist" :key="index"
                    :title="item.sequenceno+' '+item.station"
                    icon="location-o"
            />
          </van-cell-group>
        </van-tab>
        <van-tab title="返城">
          <van-cell :title="returnitem" :label="returninfo" />
          <van-cell-group>
            <van-cell
                    v-for="(item, index) in returnlist" :key="index"
                    :title="item.sequenceno+' '+item.station"
                    icon="location-o"
            />
          </van-cell-group>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
export default {
  name: 'line_query',
  data () {
    return {
      value: '',
      active: 0,
      golist: [],
      returnlist: [],
      cityname: this.$route.query.name,
      goitem: '请输入线路号',
      goinfo: '',
      returnitem: '请输入线路号',
      returninfo: ''
    }
  },
  methods: {
    init () {},
    info (item) {
      console.log(item.id)
      window.location.href = 'tel:' + item.mobile
      // this.$router.push({
      //   name: 'news_detail',
      //   query: {
      //     'id': item.id
      //   }
      // })
    },
    onSearch () {
      console.log('search')
      if (this.$route.query.cityid === '' || this.$route.query.cityid === undefined || this.$route.query.cityid === null) {
        this.$router.push({
          name: 'line_query',
          query: {}
        })
      }
      this.$http({
        fun: 'transitline',
        cityid: this.$route.query.cityid,
        transitno: this.value,
        cb: res => {
          this.goitem = res[0].startstation + '-' + res[0].endstation
          this.goinfo = res[0].timetable
          this.golist = res[0].list
          this.returnitem = res[1].startstation + '-' + res[1].endstation
          this.returninfo = res[1].timetable
          this.returnlist = res[1].list
          console.log(this.goitem)
        }
      })
    }
  },

  mounted () {
    this.init()
  }
}
</script>

<style src="./index.css" scoped>
</style>
